﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LTJ.Config;
using LTJ.Common;
using LTJ.Data;
using LTJ.FrameWork;
using LTJ.Entity;

namespace uswinweb
{
    public partial class pwd_update :AdminPage
    {
        public int userid = Utils.StrToInt(FrameWorkUtil.GetCookie("userid"), -1);
        public string username = LTJ.Common.Utils.UrlDecode(FrameWorkUtil.GetCookie("username").ToString());
        public GeneralConfigInfo config;
        protected void Page_Load(object sender, EventArgs e)
        {
            config = GeneralConfigs.GetConfig();
            if (userid == -1)
            {
                Context.Response.Redirect(config.Weburl + "index.aspx");
                return;
            }
            if (SASRequest.IsPost())
            {
                UpdatePwd();
            }

        }
        protected void UpdatePwd()
        {
            UserInfo uInfo = Users.GetUser(userid);
            string opwd = SASRequest.GetFormString("old_pwd");
            string npwd = SASRequest.GetFormString("new_pwd");
            if (Users.CheckPassword(username, opwd, true) < 0)
            {
                base.RegisterStartupScript("PAGETEMPLATE", "原密码错误！");
            }
            else
            {
                uInfo.pass = LTJ.Common.Utils.MD5(npwd);
                bool msg = Users.UpdateUser(uInfo);
                if (msg == true)
                {
                    base.RegisterStartupScript("PAGE", "parent.Lightview.hide();");
                }
                else
                {
                    base.RegisterStartupScript("PAGETEMPLATE", "更新失败！");
                }
            }
            
        }
    }
}